//
//  SISSPropertyCertificateViewController.m
//  SISSAPP
//
//  Created by 优房网 on 2017/3/27.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSPropertyCertificateViewController.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "SISSPhotoBrowser.h"


static NSInteger baseTag = 100;
@interface SISSPropertyCertificateViewController ()

/** 图片地址数组 */
@property (strong, nonatomic) NSMutableArray *urlsArr;

@end

@implementation SISSPropertyCertificateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(back)];
   
   
}

- (NSMutableArray *)urlsArr {
    
    if (_urlsArr == nil) {
        _urlsArr = [[NSMutableArray alloc] init];
    }
    return _urlsArr;
}

- (void)setupSubviews {
    
    [super setupSubviews];
    
    for (int i = 0; i < 2; i++) {
        
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(i * 66 + 40, 77, 66, 66)];
        [self.view addSubview:imageView];
        [self.urlsArr addObject:self.propertyFileArr[i].propertyPic];
        [imageView sd_setImageWithURL:[NSURL URLWithString:self.propertyFileArr[i].propertyPic] placeholderImage:[UIImage imageNamed:@"头像"]];
        imageView.tag = i + baseTag;
        imageView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureAction:)];
        [imageView addGestureRecognizer:tapGesture];
    }
}

- (void)back {
    
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)tapGestureAction:(UITapGestureRecognizer *)tap {
    
    // 拿到点击的视图
    UIImageView *imageView = (UIImageView *)tap.view;
    // 根据imageView到index
    long  index = imageView.tag - baseTag;

    SISSPhotoBrowser *photoBrowser = [[SISSPhotoBrowser alloc] init];
    photoBrowser.index = index;
    photoBrowser.urls = self.urlsArr;
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:photoBrowser];
    navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:navigationController animated:YES completion:nil];
}


@end
